package com.sumainfor.common.entity;

import com.sumainfor.common.exception.TCException;
import lombok.Data;
import lombok.extern.log4j.Log4j2;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @Author PuaChen
 * 型号表中
 * 供应商相关   json数组
 * {[供应商编号,供应商库存,库存预警数,单价]}
 * @Create 2018-11-16 11:38
 */
@Data
@Log4j2
public class MoSupplierObject implements Serializable {
    private String supplierId;
    private int storeCount;
    private int errorCount;
    private BigDecimal price;

    public MoSupplierObject(String supplierId, int storeCount, int errorCount, BigDecimal price) {
        this.supplierId = supplierId;
        this.storeCount = storeCount;
        this.errorCount = errorCount;
        this.price = price;
    }

    public MoSupplierObject() {
    }

    /**
     * 判断是否是 警告状态l
     *
     * @return
     */
    public boolean isWarning() {
        return this.storeCount <= this.errorCount;
    }

    /**
     * 添加新库存
     *
     * @param count
     */
    public void addStoreCount(int count) {
        this.storeCount += count;
    }

    /**
     * 库存出库的操作
     *
     * @param count
     */
    public void subStoreCount(int count) {
        if (this.storeCount < count) {
            //大于供应商库存出错的情况下
            log.error("出库失败,出库数量不能大于库存的数量 现库存数{} ,出库数:{}", this.storeCount, count);
            throw new TCException("出库失败,当前商品库存数不足请去采购足够的商品再次发起出库操作!");
        }
        this.storeCount -= count;
    }
}
